package com.gitee.wsl.mathematics.vector.ext

import com.gitee.wsl.mathematics.vector.Vector
import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.mathematics.vector.vec3.Vector3
import com.gitee.wsl.mathematics.vector.vec4.Vector4

infix fun<T:Number> Vector<T, *>.dot(other: Vector<T, *>) = proxy.foldIndexed(zero){index,acc,x->acc + x * other.proxy[index]}

infix fun<T:Number> Vector2<T, *>.dot(other: Vector2<T, *>) = x * other.x + y * other.y
infix fun<T:Number> Vector2<T, *>.dot(other: Vector3<T, *>) = x * other.x + y * other.y
infix fun<T:Number> Vector2<T, *>.dot(other: Vector4<T, *>) = x * other.x + y * other.y

infix fun<T:Number> Vector3<T, *>.dot(other: Vector2<T, *>) = x * other.x + y * other.y
infix fun<T:Number> Vector3<T, *>.dot(other: Vector3<T, *>) = x * other.x + y * other.y + z * other.z
infix fun<T:Number> Vector3<T, *>.dot(other: Vector4<T, *>) = x * other.x + y * other.y + z * other.z

infix fun<T:Number> Vector4<T, *>.dot(other: Vector2<T, *>) = x * other.x + y * other.y
infix fun<T:Number> Vector4<T, *>.dot(other: Vector3<T, *>) = x * other.x + y * other.y + z * other.z
infix fun<T:Number> Vector4<T, *>.dot(other: Vector4<T, *>) = x * other.x + y * other.y + z * other.z + w * other.w